<%--
 * @description: 公共引入页 其他所有页面 必须通过此方式引入资源
 --%>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ include file="laytaglibs.jsp" %>
<%@ page import="top.infopub.security.util.SessionUserUtils" %>
<%
    request.setAttribute("loginUserName", SessionUserUtils.getSessionUserName());
    request.setAttribute("fileHttpPre", request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort());
%>
<!DOCTYPE html>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
      content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<link rel="icon" href="${ctx}/resources/images/favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="${ctx}/resources/images/favicon.ico" type="image/x-icon"/>
<link rel="stylesheet" href="${ctx}/resources/layuiadmin/layui/css/layui.css" media="all">
<link rel="stylesheet" href="${ctx}/resources/layuiadmin/style/admin.css" media="all">
<link rel="stylesheet" href="${ctx}/resources/layuiadmin/style/login.css" media="all">
<script type="text/javascript" src="${ctx}/resources/layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/public/publicSetup.js"></script>
<style>
    .layui-form-select dl {
        max-height: 150px;
    }

    .layui-upload {
        float: left;
        margin-left: 10px;
    }

    .layui-upload-img-div {
        position: relative;
        width: 92px;
        height: 140px;
        float: left;
        margin-left: 10px
    }

    .layui-upload-img {
        width: 92px;
        height: 92px;
        margin: 0 10px 10px 0;
    }

    .mask {
        position: absolute;
        top: 70px;
        left: 0;
        width: 92px;
        height: 22px;
        background: rgba(101, 101, 101, 0.6);
        color: #ffffff;
        opacity: 0;
    }

    .layui-disabled, .layui-disabled:hover {
        color: #000000 !important;
    }

    .layui-select-disabled .layui-disabled {
        border: 0 !important;
    }

    .layui-select-disabled .layui-edge {
        display: none;
    }

    .layui-checkbox-disbaled[lay-skin="primary"] span {
        color: rgb(102, 102, 102);
    }

    .layui-upload-img-div:hover .mask {
        opacity: 1;
    }

    .layui-upload-img-div a {
        text-align: center;
        color: #fff;
        margin-left: 12px;
    }

    .layui-upload-img-div p {
        text-align: center;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
    }
</style>
<script src="${ctx}/resources/vue-element-lib/jquery.js"></script>
<script type="text/javascript">
    // 上下文路径
    var basePath = "${ctx}";
    // 为空的占位符
    var global_null_tip = "--";

    function clean_form(formId) {
        layui.$(':input', '#' + formId)
            .not(':button, :submit, :reset, :hidden')
            .val('')
            .removeAttr('checked')
            .removeAttr('selected');
    }

    function reset_form(formId) {
        layui.$(':input', '#' + formId)
            .not(':button, :submit, :reset')
            .val('');
    }

    function reset_form_not(formId, notId) {
        layui.$(':input', '#' + formId)
            .not(':button, :submit, :reset')
            .not('#' + notId)
            .val('');
    }

    function trimData(data) {
        var queryTrimData = new Object();
        layui.$.each(data.field, function (i, val) {
            queryTrimData[i] = layui.$.trim(val);
        });
        //layer.msg(JSON.stringify(queryTrimData));
        return queryTrimData;
    }

    // 转成万 为单位
    function convertTents(val) {
        if (val == null) {
            return global_null_tip;
        } else {
            var vals = (val + "").split(".");
            if (vals.length > 1) {
                val = vals[0] / 10000;
                val = val.toFixed(4);
                return val + vals[1];
            } else {
                return (val / 10000);
            }
        }
    }

    /**
     * 将数值四舍五入(保留2位小数)后格式化成金额形式
     * @param num 数值(Number或者String)
     * @return 金额格式的字符串,如'1,234,567.45'
     * @type String
     */
    function formatCurrency(num) {
        if (num == undefined) num = "0";
        num = num.toString().replace(/\$|\,/g, '');
        if (isNaN(num))
            num = "0";
        sign = (num == (num = Math.abs(num)));
        num = Math.floor(num * 100 + 0.50000000001);
        cents = num % 100;
        num = Math.floor(num / 100).toString();
        if (cents < 10)
            cents = "0" + cents;
        for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
            num = num.substring(0, num.length - (4 * i + 3)) + ',' +
                num.substring(num.length - (4 * i + 3));
        if (cents.toString() == '00') {
            return (((sign) ? '' : '-') + num);
        } else if (cents.toString().substring(2, 1) == '0') {
            return (((sign) ? '' : '-') + num + '.' + cents.toString().substring(0, 1));
        } else {
            return (((sign) ? '' : '-') + num + '.' + cents);
        }
    }

    //数字转为中文大写
    function convertCurrency(currencyDigits) {
        var $ = layui.$;
        // Constants:
        var MAXIMUM_NUMBER = 999999999999.99;
        // Predefine the radix characters and currency symbols for output:
        var CN_ZERO = "零";
        var CN_ONE = "壹";
        var CN_TWO = "贰";
        var CN_THREE = "叁";
        var CN_FOUR = "肆";
        var CN_FIVE = "伍";
        var CN_SIX = "陆";
        var CN_SEVEN = "柒";
        var CN_EIGHT = "捌";
        var CN_NINE = "玖";
        var CN_TEN = "拾";
        var CN_HUNDRED = "佰";
        var CN_THOUSAND = "仟";
        var CN_TEN_THOUSAND = "万";
        var CN_HUNDRED_MILLION = "亿";
        var CN_SYMBOL = "";
        var CN_DOLLAR = "元";
        var CN_TEN_CENT = "角";
        var CN_CENT = "分";
        var CN_INTEGER = "整";

        // Variables:
        var integral;    // Represent integral part of digit number.
        var decimal;    // Represent decimal part of digit number.
        var outputCharacters;    // The output result.
        var parts;
        var digits, radices, bigRadices, decimals;
        var zeroCount;
        var i, p, d, ds;
        var quotient, modulus;

        // Validate input string:
        currencyDigits = currencyDigits.toString();
        if (currencyDigits == "") {
            layer.msg("不能为空，请输入数字金额~");
            return "大写金额";
        }
        if (currencyDigits.match(/[^-?,.\d]/) != null) {
            layer.msg("输入的字符无效~");
            return "大写金额";
        }
        if ((currencyDigits).match(/^([-]?)((\d{1,3}(,\d{3})*(.((\d{3},)*\d{1,3}))?)|(\d+(.\d+)?))$/) == null) {
            layer.msg("请输入正确的数字金额~");
            return "大写金额";
        }

        // Normalize the format of input digits:
        currencyDigits = currencyDigits.replace(/,/g, "");    // Remove comma delimiters.
        currencyDigits = currencyDigits.replace(/^0+/, "");    // Trim zeros at the beginning.
        // Assert the number is not greater than the maximum number.
        if (Number(currencyDigits) > MAXIMUM_NUMBER) {
            layer.msg("数字过大，无法转换~");
            return "大写金额";
        }

        var fuhao = (currencyDigits.toString().indexOf("-") == 0 ? "负" : "");
        if (fuhao == "负") {
            currencyDigits = currencyDigits.substring(1, currencyDigits.length);
        }
        // Process the coversion from currency digits to characters:
        // Separate integral and decimal parts before processing coversion:
        parts = currencyDigits.split(".");
        if (parts.length > 1) {
            integral = parts[0];
            decimal = parts[1];
            // Cut down redundant decimal digits that are after the second.
            decimal = decimal.substr(0, 2);
        } else {
            integral = parts[0];
            decimal = "";
        }
        // Prepare the characters corresponding to the digits:
        digits = new Array(CN_ZERO, CN_ONE, CN_TWO, CN_THREE, CN_FOUR, CN_FIVE, CN_SIX, CN_SEVEN, CN_EIGHT, CN_NINE);
        radices = new Array("", CN_TEN, CN_HUNDRED, CN_THOUSAND);
        bigRadices = new Array("", CN_TEN_THOUSAND, CN_HUNDRED_MILLION);
        decimals = new Array(CN_TEN_CENT, CN_CENT);
        // Start processing:
        outputCharacters = "";
        // Process integral part if it is larger than 0:
        if (Number(integral) > 0) {
            zeroCount = 0;
            for (i = 0; i < integral.length; i++) {
                p = integral.length - i - 1;
                d = integral.substr(i, 1);
                quotient = p / 4;
                modulus = p % 4;
                if (d == "0") {
                    zeroCount++;
                } else {
                    if (zeroCount > 0) {
                        outputCharacters += digits[0];
                    }
                    zeroCount = 0;
                    outputCharacters += digits[Number(d)] + radices[modulus];
                }
                if (modulus == 0 && zeroCount < 4) {
                    outputCharacters += bigRadices[quotient];
                }
            }
            outputCharacters += CN_DOLLAR;
        }
        // Process decimal part if there is:
        if (decimal != "") {
            for (i = 0; i < decimal.length; i++) {
                d = decimal.substr(i, 1);
                ds = decimal.substr(-1, 1);
                if (d == 0) {
                    if (ds == 0) {
                        outputCharacters += "";
                    } else {
                        outputCharacters += digits[Number(d)];
                    }
                } else {

                    outputCharacters += digits[Number(d)] + decimals[i];

                }
            }
        }
        // Confirm and return the final output string:
        if (outputCharacters == "") {
            outputCharacters = CN_ZERO + CN_DOLLAR;
        }
        if (decimal == "") {
            outputCharacters += CN_INTEGER;
        }
        outputCharacters = fuhao + CN_SYMBOL + outputCharacters;
        return outputCharacters;
    }

    function formatNum(num) {
        var str = num.toString();
        if (-1 == str.indexOf(".")) {
            str = str + ".00"
        }
        if (-1 != str.indexOf(",")) {
            str = str.replace(new RegExp(',', "g"), "")
        }
        var intSum = str.substring(0, str.indexOf(".")).replace(
            /\B(?=(?:\d{3})+$)/g, ',');
        var dot = str.substring(str.length, str.indexOf("."));
        var ret = intSum + dot;
        return ret;
    }

    function setDecimalPlaces(f, digit) {
        var m = Math.pow(10, digit);
        return Math.round(f * m) / m;
    }

    function yuanToWanyuan(amount) {
        return formatNum(setDecimalPlaces(amount / 10000, 2))
    }

    //元转万元 带千分位
    //console.log(yuanToWanyuan(10026780000333));

    //金额小写转大写，并弹出提示
    function arabiaToCN(obj, unit) {
        if (obj.value == '' || obj.value == null || obj.value == 0) {
            return;
        }
        var rgx = /^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;

        var boolrgx = rgx.test(obj.value);// true
        if (!boolrgx) {
            return;
        } else {
            var cnValue = '';
            if (unit == 2) {//单位为万元
                cnValue = convertCurrency((obj.value * 10000).toFixed(0));
            } else {
                cnValue = convertCurrency(obj.value);
            }
            layui.layer.tips(cnValue, obj, {
                tips: 1,
                time: 5000 //5秒关闭（如果不配置，默认是3秒）
            });
        }
    }


    function zAjax(url, data) {
        return new Promise((resolve, reject) => {
            $.ajax({
                type: 'post',
                data: data,
                url: basePath + url,
                success: function (res) {
                    resolve(res)
                }
            })
        })
    }

    function showFile(fileList) {
        if (fileList && fileList.length > 0) {
            fileArr = fileList;
            for (let i in fileList) {
                let contractInfo = fileList[i];
                let arr = contractInfo.split("|");
                let imgSrc = "";
                let suffix = arr[1].substring(arr[1].lastIndexOf(".") + 1, arr[1].length);
                if (suffix == 'jpg' || suffix == 'png') {
                    imgSrc = "${fileHttpPre}/" + arr[3];
                } else {
                    imgSrc = "${ctx}/resources/images/" + suffix + ".jpg";
                }
                $('#' + arr[0] + '-upload-more-list')
                    .append('<div class="layui-upload-img-div" id="upload_img_' + arr[2] + '"><img src="' + imgSrc + '" title="'
                        + arr[1] + '" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\'' + "${fileHttpPre}"
                        + arr[3] + '\');">查看</a><a href="javascript:void(0)" onclick="del(\''
                        + arr[2] + '\')";>删除</a></div><p>' + arr[1] + '</p><input type="hidden" value="'
                        + contractInfo + '" id="fileAtt_' + arr[2] + '" name="fileAtts" ></input></div> ');
            }
        }
    }

    //多文件列表示例
    ;(function () {
        //定义构造函数
        var Upfile = function (ele, type, opt) {
            this.defaults = {
                //elem:‘#uploadPic‘	//绑定元素
                elem: $(ele)	//绑定元素
                , url: basePath + '/contractInfo/uploadAtt/',
                data: {
                    types: type
                },
                multiple: true,
                accept: 'file',
                acceptMime: 'application/zip,application/x-rar-compressed,image/jpeg,image/png,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf',

                method: 'post',
                before: function (obj) { //obj参数包含的信息
                    layer.load(); //上传loading
                },
                done: function (res) {
                    //如果上传失败
                    if (res.code > 0) {
                        layer.closeAll('loading'); //关闭loading
                        return layer.msg(res.msg, {icon: 7});
                    }
                    //上传完毕
                    if (res.entity != null && res.entity.length > 0) {
                        fileArr.push(res.entity[0])
                        for (var i in res.entity) {
                            var contractInfo = res.entity[i];
                            var arr = contractInfo.split("|");
                            var imgSrc = "";
                            var suffix = arr[1].substring(arr[1].lastIndexOf(".") + 1, arr[1].length);
                            if (suffix == 'jpg' || suffix == 'png') {
                                imgSrc = "${fileHttpPre}/" + arr[3];
                            } else {
                                imgSrc = "${ctx}/resources/images/" + suffix + ".jpg";
                            }
                            $('#' + type + '-upload-more-list')
                                .append('<div class="layui-upload-img-div" id="upload_img_' + arr[2] + '"><img src="' + imgSrc + '" title="'
                                    + arr[1] + '" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\'' + "${fileHttpPre}"
                                    + arr[3] + '\');">查看</a><a href="javascript:void(0)" onclick="del(\''
                                    + arr[2] + '\')";>删除</a></div><p>' + arr[1] + '</p><input type="hidden" value="'
                                    + contractInfo + '" id="fileAtt_' + arr[2] + '" name="fileAtts" ></input></div> ');
                        }
                    }
                },
                allDone: function (obj) { //当文件全部被提交后，才触发
                    layer.closeAll('loading'); //关闭loading
                },
                error: function () {
                    layer.closeAll('loading'); //关闭loading
                    //上传失败
                    layer.msg("上传失败，请稍后再试~", {icon: 7});
                }
            }
            this.options = $.extend({}, this.defaults, opt);
        };

        //定义方法
        Upfile.prototype = {
            init: function () {
                var _this = this;
                return layui.use('upload', function () {
                    var upload = layui.upload;

                    //执行实例
                    var uploadInst = upload.render(_this.options);
                });
            }
        };

        //在插件中使用对象
        $.fn.upfile = function (options) {
            var upfile = new Upfile(this, options);
            return upfile.init();
        }
    })();

    function numToStr(obj) {
        for (let i in obj) {
            if (obj[i] === 0) {
                obj[i] = '0'
            }
        }
        return obj;
    }

	//数组扁平化
	function flatten(arr) {
		return arr.reduce((result, item) => {
			return result.concat(Array.isArray(item) ? flatten(item) : item);
		}, []);
	}

	function total(list, itemType) {
		let flag = 0,
				data = [];
		for (let i = 0; i < list.length; i++) {
			let az = '';
			for (let j = 0; j < data.length; j++) {
				if (data[j][0][itemType] == list[i][itemType]) {
					flag = 1;
					az = j;
					break;
				}
			}
			if (flag == 1) {
				data[az].push(list[i]);
				flag = 0;
			} else if (flag == 0) {
				wdy = new Array();
				wdy.push(list[i]);
				data.push(wdy);
			}
		}
		return data;
	}

</script>
